home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_tut / tasking.dum < prev    next >
Text File  |  1996-01-30  |  1KB  |  36 lines

  1. with text_io, calendar; use text_io, calendar;
  2. procedure tasking is
  3.    interval        : constant duration := 5.0;
  4.    total_intervals : constant positive := 9;
  5.    start_time      : constant time := clock;
  6.    quitting_time   : constant time := start_time +
  7.                                              total_intervals*interval;
  8.    next_time       : time := start_time;
  9.    task type tick is
  10.       entry make_noise;
  11.       entry shutdown;
  12.    end tick;
  13.    t               : tick;
  14.    task body tick is
  15.       quit : boolean := false;
  16.    begin
  17.       while not quit loop
  18.          select
  19.             accept make_noise do
  20.                put_line("Tick!");
  21.             end make_noise;
  22.          or
  23.             accept shutdown;
  24.             quit := true;
  25.          end select;
  26.       end loop;
  27.    end tick;
  28. begin
  29.    while next_time < quitting_time loop
  30.       t.make_noise;
  31.       next_time := next_time + interval;
  32.       put_line("(5-second delay)"); delay next_time - clock;
  33.    end loop;
  34.    t.shutdown;
  35. end tasking;
  36.